home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / AOCE / Create AOCE Business Card / CreateBusinessCard.c
Encoding:
C/C++ Source or Header  |  1994-08-09  |  3.7 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*****************************************************************
  2.  *    CreateBusinessCard.c
  3.  *
  4.  *    8/9/94
  5.  *    By: Scott Kuechle
  6.  *    Apple Developer Technical Support
  7.  *
  8.  *    Written in MPW 3.3.1 C
  9.  *    Compiles with 68K interfaces
  10.  *
  11.  *    Description:
  12.  *
  13.  *    Shows how to create a PowerTalk business card anywhere on
  14.  *    a given volume. Just create an FSSpec and call CreateBusinessCard()
  15.  *    with that FSSpec.
  16.  *
  17.  *****************************************************************/
  18.  
  19.  
  20.  
  21. #include <OCE.h>
  22. #include <OCEAuthDir.h>
  23. #include <OCEMessaging.h>
  24. #include <OCEStandardDirectory.h>
  25.  
  26. #include <files.h>
  27. #include <errors.h>
  28.  
  29.  
  30.  
  31. OSErr GetIdentity();
  32. OSErr DoAuthentication();
  33. OSErr CreateBusinessCard(FSSpecPtr fsspec);
  34.  
  35.  
  36.    /* globals */
  37. AuthIdentity           gIdentity;
  38. RString gMyRecName  =   {smRoman,11,{"RecNameHere"}};
  39. #define    gPCatName       "\pDisk:BusinessCardName"        // put pathname of business card here
  40.  
  41.  
  42. /*****************************************************************
  43.  *    main
  44.  *
  45.  *
  46.  *****************************************************************/
  47.  
  48. void main()
  49. {
  50. OSErr err;
  51. FSSpec fsspec;
  52.  
  53.     err = FSMakeFSSpec(0,0,gPCatName,&fsspec);
  54.     if (err == fnfErr) 
  55.         err = CreateBusinessCard(&fsspec);
  56. }
  57.  
  58.  
  59. /*****************************************************************
  60.  *    GetIdentity
  61.  *
  62.  *    authenticate the user
  63.  *****************************************************************/
  64.  
  65. OSErr GetIdentity()
  66. {
  67. OSErr err;
  68. SDPIdentityKind selectedKind;
  69.  
  70.     err = SDPPromptForID(&gIdentity,
  71.                          NULL,
  72.                          NULL,
  73.                          "\pPlease enter the password for your master key",
  74.                          OCEGetIndRecordType(kUserRecTypeNum),
  75.                          kSDPLocalIdentityMask,
  76.                          &selectedKind,
  77.                          NULL,
  78.                          0);   /* ignored */
  79.     return err;
  80. }
  81.  
  82.  
  83. /*****************************************************************
  84.  *    DoAuthentication
  85.  *
  86.  *    check for user authentication
  87.  *****************************************************************/
  88. OSErr DoAuthentication()
  89. {
  90. OSErr err;
  91. AuthGetLocalIdentityPB pb;
  92.  
  93.       // first check if the user has already been authenticated. If so
  94.       // we dont want to bother with authenticating again.
  95.     err = AuthGetLocalIdentity((AuthParamBlockPtr)&pb,false);
  96.  
  97.     if (err != noErr)
  98.         // user has not been authenticated, so let's do it now
  99.       err = GetIdentity();
  100.     else
  101.         // user has already been authenticated
  102.       gIdentity = pb.theLocalIdentity;
  103.     
  104.     return err;
  105. }
  106.  
  107. /*****************************************************************
  108.  *    CreateBusinessCard
  109.  *
  110.  *    build the actual business card
  111.  *****************************************************************/
  112.  
  113. OSErr CreateBusinessCard(FSSpecPtr fsspec)
  114. {
  115. OSErr         err;
  116. DirParamBlock pb;
  117. RecordID      rid;
  118.  
  119.  
  120.     
  121.     pb.createPersonalDirectoryPB.fsSpec = fsspec;
  122.     pb.createPersonalDirectoryPB.fdType = kBusinessCardFileType;
  123.     pb.createPersonalDirectoryPB.fdCreator = kPersonalDirectoryFileCreator;
  124.     err = DirCreatePersonalDirectory(&pb);
  125.     if (err == noErr)
  126.     {
  127.         pb.openPersonalDirectoryPB.fsSpec = fsspec;
  128.         pb.openPersonalDirectoryPB.accessRequested = fsRdWrPerm;
  129.         err = DirOpenPersonalDirectory(&pb);
  130.         if (err == noErr)
  131.         {
  132.             err = DoAuthentication();
  133.             if (err == noErr)
  134.             {
  135.                 rid.local.cid.source = 0;
  136.                 rid.local.cid.seq = 0;
  137.                 rid.local.recordType = OCEGetIndRecordType(kUserRecTypeNum);
  138.                 rid.local.recordName = &gMyRecName;
  139.                 
  140.                 pb.addRecordPB.serverHint.aNet = 0;
  141.                 pb.addRecordPB.serverHint.aNode = 0;
  142.                 pb.addRecordPB.serverHint.aSocket = 0;
  143.                 pb.addRecordPB.identity = gIdentity;
  144.                 pb.addRecordPB.aRecord = &rid;
  145.                 pb.addRecordPB.allowDuplicate = false;
  146.                 
  147.                 err = DirAddRecord(&pb,false);
  148.             }
  149.         DirClosePersonalDirectory(&pb);
  150.         }
  151.     }
  152.  
  153.     return (err);
  154. }
  155.